﻿<!DOCTYPE html>
<html>
	<head>
		<!--<title>创建扩展属性</title>-->
        $css()
	</head>
	<body>
        <div id="category_extends" class="form entityForm" style="min-width:300px;max-width:600px;">
            <form id="form3">
                <dl id="category">
                    <dt>栏目名称：</dt>
                    <dd field="Name"></dd>
                </dl>
                <dl id="extends">
                    <dt>扩展属性：</dt>
                    <dd>
                        <span id="extendPanel"></span>
                    </dd>
                </dl>
                <div class="clearfix"></div>
                <dl>
                    <dt>&nbsp;</dt>
                    <dd>
                        <a id="btn" class="btn" href="javascript:;">确定</a>
                        <a id="btn_reset" class="btn" href="javascript:;">重设</a>
                    </dd>
                </dl>
            </form>
        </div>
        <div class="form autostyle" id="extend_form">
           
        </div>
        

        $js()
        <script type="text/javascript">
            var _category=${category};
            var _extends=${json};

            var _extendForm = cms.$('category_extends');
            var _extendPanel = cms.$('extendPanel');
            cms.json.bind(_extendForm,_category);

            
            for(var i in _extends){
                _extendPanel.innerHTML+='<input type="checkbox" field="ExtendIds['+i+']" id="ck'+i
                    +'" value="'+_extends[i].ID+'"/><label for="ck'
                    +i+'">'+_extends[i].Name+'</label>&nbsp;&nbsp;';
            }
            if(_extendPanel.innerHTML==''){
                _extendPanel.innerHTML='<span style="color:red">系统还没有扩展属性，请通过栏目管理=》扩展属性进行添加！</span>';
                cms.$('btn').addAttribute('disabled','disabled');
            }
            cms.json.bind(_extendForm,_category);


            window.save= function () {
                var settedExtend=cms.json.toObject(_extendForm).ExtendIds;
                var extendIdStr='';
                var j=0;
                for(var i in settedExtend){
                    if(j++!=0) extendIdStr+=',';
                    extendIdStr+=settedExtend[i];
                }


                cms.xhr.jsonAjax('${url}',
                    'extendIds='+extendIdStr,
                    function (json) {
                        if (json.result) {
                                parent.M.alert(json.message,function () {
                            });
                        } else {
                            parent.M.alert(json.message);
                        }
                    });
            };

            cms.$('btn').onclick =save;

            cms.$('btn_reset').onclick=function(){
                document.forms["form3"].reset();
            }
        </script>
	</body>
</html>